package com.ss.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ss.model.TSysuser;
import com.ss.service.ISysUserService;

@Controller
@RequestMapping("/system")
public class SystemController {
	private JSONObject jsonObj;
	private String rows;// 每页显示的记录数
	private String page;// 当前第几页

	private ISysUserService suservice;
	private static final Logger logger = Logger
			.getLogger(SystemController.class);

	public ISysUserService getSuservice() {
		return suservice;
	}

	@Autowired
	public void setSuservice(ISysUserService suservice) {
		this.suservice = suservice;
	}

	@RequestMapping("/systemuser/getsystemusers")
	@ResponseBody
	public Map<String, Object> getSystemUsers(
			HttpServletRequest request,
			@RequestParam(required = false, defaultValue = "1", value = "page") int page,
			@RequestParam(value = "rows", required = false, defaultValue = "10") int rows) {
//		logger.info(page + " " + rows);
		List<TSysuser> list = suservice.getSysuserList(page, rows);
		if (list != null) {
			logger.info("result size is : "+list.size());
			Map<String, Object> result = new HashMap<String, Object>();
			result.put("rows", list);
			result.put("total", list.size());
			return result;
		} else
			logger.info("no sysuser exists");
			return null;

	}

	@RequestMapping("/systemuser")
	public String showSystemUsers() {

		return "systemuser";
	}

	@RequestMapping("/role")
	public String showRoleList() {

		return "role";
	}

	@RequestMapping("/role/getroles")
	public String getRoles(HttpServletRequest request) {
		int pageSize = Integer.parseInt(request.getParameter("rows"));
		int pageNum = Integer.parseInt(request.getParameter("page"));
		System.out.println(pageSize + "  " + pageNum);

		return "role";
	}

}
